import moment from 'moment'

/* 时间过滤器 - 年月日 */
export const formatTime = value => moment(value).format('YYYY-MM-DD')
export const formatTimeDate = value => moment(value).format('YYYY-MM-DD HH-mm-ss')
export const newsTime = value => moment(value).format('YYYY/MM/DD HH:mm')
export const communicationTime = value => moment(value).format('MM/DD HH:mm')
export const fileTime = value => moment(value).format('YYYY/MM/DD')

// 代理人在职时间
export const oneThejobDay = value => {
  let cTime = value.created_at.replace(/-/g, "/");
  let nTime = ''
  let nowTime = null
  
  if (value.type == '离职') {
    nTime = (value.user && value.user.leaved_at)  || value.updated_at
    nowTime = new Date(nTime.replace(/-/g, "/"))
  } else {
    nowTime = new Date();
  }

  //获取入职时间戳
 
  var createTime = new Date(cTime);
  //获取当前的时间戳
  let processingTime = ''
  //获取处理时间戳
  let cha = nowTime - createTime;
  let day = 1000 * 60 * 60 * 24;
  var month = day * 30
  let year = month * 12

  // processingTime += (cha / month).toFixed(1)
  let round2 = (cha / month).toFixed(2)
  processingTime = (Math.ceil(round2 * 10) / 10).toFixed(1)
  if (processingTime <= 0) {
    return '0.0'
  } else {
    return processingTime;
  }
}

// 专属顾问显示编号
export const processNumber = value => {
  if (value.email_work) {
    return value.email_work.split("@")[0].slice(-3)
  } else {
    return value.name
  }
}

//代理人显示编号
export const agentNumber = value => {
  if (value) {
    if (value.email_work) {
      return value.email_work.split("@")[0].slice(-3)
    } else {
      return ''
    }
  } else {
    return ''
  }
}

// 代理人显示编号加名字
export const agentNumAddName = value => {
  if (value) {
    if (value.email_work) {
      return `${value.name}（${value.email_work.split("@")[0].slice(-3)}）`
    } else {
      return value.name
    }
  } else {
    return ''
  }
}

export const getNullVal = value => {
  if (!value) {
    return '无'
  } else {
    return value
  }

}

// 答复列表发文日期
export const getPost = value => {
  if (value.statuss) {
    let sta = value.statuss
    if (sta[sta.findIndex(v => v.id == 20)]) {
      return sta[sta.findIndex(v => v.id == 20)].pivot.created_at
    } else {
      return value.updated_at
    }
  } else {
    return value.updated_at
  }
}

// 答复列表更新日期
export const getAnswerUpdateTime = value => {
  if (value.statuss) {
    let sta = value.statuss
    if (sta[sta.findIndex(v => v.id == 21)]) {
      return sta[sta.findIndex(v => v.id == 21)].pivot.created_at
    } else {
      return value.updated_at
    }
  } else {
    return value.updated_at
  }
}

// 日期filter
export const dayFilter = value => {
  if (value == 0) {
    return value = '-'
  } else {
    return value
  }
}



// 类型字母转文字
export const typeFilter = value => {
  if (value == 'S') {
    return '实用新型';
  } else if (value == 'F') {
    return '发明专利';
  } else if (value == 'W') {
    return '外观设计'
  }
}
// 类型字母转文字 小写
export const typeFilterLowercase = value => {
  switch (value) {
    case 's':
      return '实用新型';
    case 'f':
      return '发明专利';
    case 'w':
      return '外观设计'
  }
}
// 类型字母转文字 小写
export const toType = value => {
  switch (value) {
    case 1:
      return '支付宝';
    case 2:
      return '银行卡';
  }
}

// 活动状态转数字
export const activityStatus = value => {
  switch (value) {
    case 1:
      return '进行中';
    case 2:
      return '未通过';
    case 3:
      return '待审核'
    case 4:
      return '未开始'
    case 5:
      return '已结束'
    case 6:
      return '已下线'
  }
}

export const activityStatusColor = value => {
  switch (value) {
    case 1:
      return 'font_success';
    case 5:
      return 'font_danger'
    case 6:
      return 'font_danger'
  }
}

// 用户余额type 对应状态
export const userPurseType = value => {
  switch (value) {
    case 0:
      return '余额提现';
    case 1:
      return '积分兑换';
    case 2:
      return '余额充值';
    case 3:
      return '案件支付';
    case 4:
      return '案件退款';
    case 5:
      return '升级VIP';
    case 6:
      return '投诉建议';
    case 7:
      return '投诉建议';
    case 8:
      return '打赏';
    case 9:
      return '打赏';
    case 10:
      return '打赏';
    case 11:
      return '成就奖励';
    case 12:
      return '提现扣税';
    case 13:
      return '平台奖励';
    case 22:
      return '购买VIP';
  }
}
// 用户积分type 对应状态
export const userPursePointsType = value => {
  switch (value) {
    case 1:
      return '申报案件';
    case 2:
      return '推荐奖励';
    case 3:
      return '积分兑换';
    case 4:
      return '案件退款';
    case 5:
      return '余额充值';
    case 6:
      return '年终清理积分';
    case 7:
      return '案件评分';
    case 8:
      return '投诉建议';
    case 9:
      return '案件评分';
    case 10:
      return '活动奖励';
    case 11:
      return '购买VIP';
    case 12:
      return '兑换优惠券';
    case 13:
      return '兑换商品';
    case 14:
      return '案件抵扣';
    case 15:
      return '活动奖励';
    case 30:
      return '成就奖励';
    case 31:
      return '成就奖励';
    case 32:
      return '成就奖励';
    case 33:
      return '成就奖励';
    case 34:
      return '成就奖励';
    case 35:
      return '成就奖励';
    case 36:
      return '成就奖励';
    case 37:
      return '成就奖励';
    case 38:
      return '成就奖励';
    case 39:
      return '成就奖励';
  }
}
// 代理人钱包type 对应状态
export const agentPurseType = value => {
  switch (value) {
    case 0:
      return '余额提现';
    case 1:
      return '推荐奖励';
    case 2:
      return '案件撰写';
    case 3:
      return '平台惩戒';
    case 4:
      return '平台奖励';
    case 5:
      return '余额充值';
    case 6:
      return '扣款申诉';
    case 7:
      return '案件支付';
    case 8:
      return '案件退款';
    case 9:
      return '优秀案件奖励';
    case 10:
      return '线下打款';
    case 11:
      return '案件授权';
    case 12:
      return '答复/补正';
    case 13:
      return '答复/补正';
    case 14:
      return '出师奖励';
    case 15:
      return '发明人打赏';
    case 16:
      return '投诉建议';
    case 17:
      return '投诉建议';
    case 18:
      return '案件支付';
    case 19:
      return '案件支付';
    case 20:
      return '成就奖励';
    case 21:
      return '案件驳回';
    case 22:
      return 'VIP返现';
    case 23:
      return '购买VIP';
  }
}

// 钱包支付方式显示
export const payMethod = value => {
  if (value.order_pay) {
    switch (value.order_pay.pay_type) {
      case 1:
        return '银联';
      case 2:
        return '支付宝';
      case 3:
        return '微信';
      case 4:
        return '余额';
    }
  } else if (value.recharge) {
    switch (value.recharge.pay_type) {
      case 1:
        return '银联';
      case 2:
        return '支付宝';
      case 3:
        return '微信';
      case 4:
        return '余额';
    }
  } else {
    return ''
  }
}


// 国知局后发明人提交时间
export const usetSubmitTime = value => {
  if (value.order) {
    return value.order.created_at
  } else {
    return '导入数据'
  }
}
// 代理人申诉列表状态
export const appealStatus = value => {
  switch (value) {
    case 0:
      return '待审核';
    case 1:
      return '通过';
    case 2:
      return '未通过';
  }
}
// 缴费状态
export const payStatus = value => {
  switch (value) {
    case 0:
      return '已缴费';
    case 1:
      return '已缴费';
    case 2:
      return '未缴费';
    case 3:
      return '已退款';
  }
}

export const orderPay = value => {
  if (value) {
    switch (value.pay_status) {
      case 0:
        return '未缴费';
      case 1:
        return '支付中';
      case 2:
        return '已缴费';
      case 3:
        return '退款中';
      case 4:
        return '已退款';
    }
  } else {
    return '未缴费'
  }
}

// 导师审核状态
export const teacherAuditorStatus = value => {
  if (value.statuss) {
    let statuss = value.statuss
    for (let i = 0; i < statuss.length; i++) {
      if (statuss[i].id == 18) {
        return '导师审核驳回'
      } else if (statuss[i].id == 17) {
        return '导师审核通过'
      } else if (statuss[i].id == 16) {
        return '导师审核中'
      } else if (value.status == '代理人撰写中' && statuss[i].id == 2) {
        return '未提交导师审核'
      } else if (value.status == '案件修改中' && statuss[i].id == 5) {
        return '未提交导师审核'
      }
    }
  }

}

// 扣款申诉审核列表
export const deductionsAppeal = value => {
  switch (value) {
    case 1:
      return '通过';
    case 2:
      return '驳回';
    case 3:
      return '待审核';
    case 4:
      return '待审核';
    case 5:
      return '驳回';
  }
}
// 用户vip等级
export const vipLevel = value => {
  switch (Number(value)) {
    case 0:
      return '普通会员';
    case 1:
      return '铜牌会员';
    case 2:
      return '银牌会员';
    case 3:
      return '金牌会员';
    case 4:
      return '钻石会员';
  }
}
// 用户vip等级兑换积分多少
export const vipLevelPoints = value => {
  switch (Number(value)) {
    case 0:
      return '0';
    case 1:
      return '1';
    case 2:
      return '3';
    case 3:
      return '5';
    case 4:
      return '10';
  }
}
// 用户vip提现次数多少
export const vipLevelCash = value => {
  switch (Number(value)) {
    case 0:
      return '0';
    case 1:
      return '1';
    case 2:
      return '1';
    case 3:
      return '2';
    case 4:
      return '4';
  }
}
export const vipexPoints = value => {
  if (value == '铜牌会员') {
    return '1';
  } else if (value == '银牌会员') {
    return '3';
  } else if (value == '金牌会员') {
    return '5';
  } else if (value == '钻石会员') {
    return '10';
  }
}
export const vipexPoints2 = value => {
  if (value == 1) {
    return '1';
  } else if (value == 2) {
    return '3';
  } else if (value == 3) {
    return '5';
  } else if (value == 4) {
    return '10';
  }
}

export const vipexBalance = value => {
  if (value == '铜牌会员') {
    return '1';
  } else if (value == '银牌会员') {
    return '1';
  } else if (value == '金牌会员') {
    return '2';
  } else if (value == '钻石会员') {
    return '4';
  }
}
// 代理人vip等级
export const agentVipLeval = value => {
  switch (value) {
    case 0:
      return '代理人';
    case 1:
      return 'VIP代理人';
  }
}

// 计算官费
export const getGovMoney = (value) => {
  let govMoney = 0
  govMoney = (Number(value.gov_money) + Number(value.power_over_money)).toFixed(2)
  return govMoney
}

// 消息列表接收角色转成角色名
export const getRoleName = (value) => {
  let roles = value.split(',')
  let rolesBack = []
  for (let i = 0; i < roles.length; i++) {
    if (roles[i] == 2) {
      rolesBack.push('代理人')
    } else if (roles[i] == 4) {
      rolesBack.push('专属顾问')
    } else if (roles[i] == 5) {
      rolesBack.push('发明人')
    } else if (roles[i] == 3) {
      rolesBack.push('审核员')
    }
  }
  return rolesBack.join(',')
}
// 私信详情 名称显示
export const getDirectDetailsName = value => {
  if (value.length >= 2) {

    return value.slice(value.length - 2)
  } else {
    return value
  }
}
// 系统消息列表判读已读未读
export const isReadOrNo = (value) => {
  if (value) {
    return false
  } else {
    return true
  }
}
// 私信消息列表判读已读未读
export const isDirectReadOrNo = (value) => {
  if (value > 0) {
    return true;
  } else {
    return false;
  }
}
// 私信消息判断身份
export const getNewsRoleName = (value) => {
  switch (Number(value)) {
    case 2:
      return '代理人';
    case 3:
      return '审核员';
    case 4:
      return '流程员';
    case 5:
      return '发明人';
  }
}
// 意见反馈type
export const opinionType = (value) => {
  switch (value) {
    case 1:
      return '平台优化';
    case 2:
      return '服务建议';
    case 3:
      return '其他';
  }
}
// 意见反馈status
export const opinionStatus = (value) => {
  switch (value) {
    case 0:
      return '处理中';
    case 1:
      return '未采纳';
    case 2:
      return '已采纳';
    case 3:
      return '恶意建议';
    case 4:
      return '初审通过';
  }
}
export const opinionStatusClass = (value) => {
  switch (value) {
    case 0:
      return 'font_warning';
    case 1:
      return 'font_danger';
    case 2:
      return 'font_success';
    case 3:
      return 'font_danger';
    case 4:
      return 'font_success';
  }
}
export const opinionStatusBtnText = (value) => {
  switch (value) {
    case 0:
      return '初审';
    case 1:
      return '未采纳';
    case 2:
      return '已采纳';
    case 3:
      return '恶意建议';
    case 4:
      return '审核';
  }
}
export const opinionStatusBtnType = (value) => {
  switch (value) {
    case 0:
      return 'warning';
    case 1:
      return 'danger';
    case 2:
      return 'success';
    case 3:
      return 'danger';
    case 4:
      return 'warning';
  }
}


// 意见反馈提交人类型
export const opinionsUserType = (value) => {
  if (value) {
    switch (value.role_id) {
      case 2:
        return '代理人';
      case 5:
        return '用户';
    }
  } else {
    return ''
  }

}

// 代理人接单等级
export const agentGrade = (value) => {
  switch (value) {
    case 1:
      return '初级';
    case 2:
      return '中级';
    case 3:
      return '高级';
  }
}
// 代理人接单等级对应类名
export const agentGradClass = (value) => {
  if (value) {
    switch (value) {
      case 1:
        return 'info-level early';
      case 2:
        return 'info-level intermediate';
      case 3:
        return 'info-level senior';
    }
  } else {
    return ''
  }
}
// 代理人接单数
export const agentIsTake = (value) => {
  if (value == 999 || value == null) {
    return '不限制接单'
  } else if (value === 0) {
    return '不可接单'
  } else {
    return value
  }
}
// 推荐码
export const channelPid = (value) => {
  if (value) {
    if (value.referral_code) {
      return value.referral_code
    } else {
      return ''
    }
  } else {
    return ''
  }

}

export const menuContHidden = value => {
  if (value) {
    return false
  } else {
    return true
  }
}

// 国知局前状态显示颜色
export const orderStatusColor = value => {
  if (value == '代理人撰写中') {
    return 'font_red'
  }
  else if (value == '案件内审中') {
    return 'font_orange'
  }
  else if (value == '案件修改中') {
    return 'font_yellow'
  }
  else if (value == '定稿文件发送中') {
    return 'font_green'
  }
  else if (value == '发明人确认定稿中') {
    return 'font_cyan'
  }
  else if (value == '上报文件上传中') {
    return 'font_blue'
  }
  else if (value == '文件格式审核中') {
    return 'font_purple'
  }
}

export const regNews = value => {
  return value.replace('&emsp;', '&nbsp;', '').replace(/<[^>]+>/g, '').replace(/&emsp;/g, "")
}

// 代理人排行类型
export const rankType = (value) => {
  switch (value) {
    case 1:
      return '案件完成数';
    case 2:
      return '返修率';
    case 3:
      return '发明数';
    case 4:
      return '评分';
    case 5:
      return '平均耗时';
    case 6:
      return '打赏金额';
    case 7:
      return '成就点';
  }
}

// 代理人评分平均分
export const getAverage = (value) => {
  return (value.total_score / 3).toFixed(1)
}

export const companyStatus = (value) => {
  switch (value) {
    case 1:
      return '审核通过';
    case 2:
      return '待审核';
    case 3:
      return '未通过';
  }
}

export const frozeStatus = (value) => {
  switch (value) {
    case 1:
      return '冻结';
    case 2:
      return '未冻结';
    case 3:
      return '待审核';
  }
}
// 活动类型
export const activityType = value => {
  switch (value) {
    case 1:
      return '系统配置';
    case 2:
      return '普通活动'
  }
}
// 活动类型
export const payType = value => {
  switch (value) {
    case 2:
      return '微信';
    case 3:
      return '支付宝'
    case 4:
      return '余额支付'
  }
}
//公司查看详情表头切换
export const getType = value => {
  switch (value) {
    case 1:
      return '申报列表';
    case 2:
      return '授权列表'
    case 3:
      return '其他机构案件'
  }
}
export const needsStatus = value => {
  switch (value) {
    case 1:
      return '有效';
    case -1:
      return '失效'
    case -2:
      return '放弃'
  }
}
export const confirmStatus = value => {
  switch (value) {
    case 1:
      return '发明人已确认';
    case 2:
      return '未确认'
    case 3:
      return '系统自动确认'
    case 4:
      return '发明人退回'
    case 5:
      return '已修改错误信息'
  }
}
export const confirmStatusColor = value => {
  switch (value) {
    case 1:
      return 'font_success';
    case 2:
      return 'font_warning'
    case 3:
      return '系统自动确认'
    case 4:
      return 'font_danger'
    case 5:
      return '已修改错误信息'
  }
}

export const needsEndTime = value => {
  let date = new Date();
  let now = date.getTime();
  let endDate = new Date(value); //设置截止时间
  let end = endDate.getTime();
  end = end + 60000
  let leftTime = end - now; //时间差
  let d, h, m, s, ms;
  if (leftTime >= 0) {
    // d = Math.floor(leftTime / 1000 / 60 / 60 / 24);
    // h = Math.floor(leftTime / 1000 / 60 / 60);
    // m = Math.floor((leftTime / 1000 / 60) % 60);
    // s = Math.floor((leftTime / 1000) % 60);
    // ms = Math.floor(leftTime % 1000);

    // // s = s + 10
    // if (ms < 100) {
    //   ms = "0" + ms;
    // }
    // if (s < 10) {
    //   s = "0" + s;
    // }
    // if (m < 10) {
    //   m = "0" + m;
    // }
    // if (h < 10) {
    //   h = "0" + h;
    // }
    //获取处理时间戳
    // let cha = nowTime - createTime;
    let day = (leftTime / 1000 / 60 / 60 / 24).toFixed(2)
    let day1 = (Math.ceil(day * 10) / 10).toFixed(1)

    return `${day1}`;
  } else {
    return '已过期'
  }
}

